# Maintainer: Ben Fuhrmannek <ben+alpine@sektioneins.de>
pkgname=tcl-curl
pkgver=7.22.0
pkgrel=0
pkgdesc="Tcl interface to cURL"
_commit="ed4856901dee2784ceeb6d2ee0d621fe05aa0134"
_reponame="tclcurl-fa"
url="https://github.com/flightaware/$_reponame"
arch="all"
license="TCL"
depends="tcl"
makedepends="curl-dev tcl-dev"
subpackages="$pkgname-doc"
source="$pkgname-$pkgver.tar.gz::https://github.com/flightaware/tclcurl-fa/archive/$_commit.tar.gz"
builddir="$srcdir/$_reponame-$_commit"

build() {
	# shellcheck disable=SC1091
	. /usr/lib/tclConfig.sh

	local extra_configure_flags
	if echo "$TCL_DEFS" | grep -q "DTCL_CFG_DO64BIT=1"; then
		extra_configure_flags="--enable-64bit"
	fi

	./configure \
		--build=$CBUILD \
		--host=$CHOST \
		--prefix=/usr \
		--sysconfdir=/etc \
		--mandir=/usr/share/man \
		--localstatedir=/var \
		--enable-threads \
		$extra_configure_flags

	make
}

check() {
	ln -s generic/tclcurl.tcl .

	# 'make test' is broken / works only after make install
	## so we start the test suite manually, which is easier than patching 'make test'
	cat <<EOT >tclsh-test.sh
#!/bin/sh
echo -e "set auto_path [list [pwd] {*}\$auto_path]\nsource {\$1}" |tclsh
EOT
	chmod +x tclsh-test.sh
	cat <<EOT |tclsh
package require tcltest
::tcltest::configure -testdir tests
::tcltest::interpreter "[pwd]/tclsh-test.sh"
exit [::tcltest::runAllTests]
EOT
}

package() {
	make -j1 DESTDIR="$pkgdir" install-binaries install-scripts install-doc
}

sha512sums="
713892700ff701937482452ef9d03af2ea73c51afc740ca0565adae608d360d2dff087d9e5b55cf0b4ea4314e4c3885e9b3250039ac4977f222383eef3122aaf  tcl-curl-7.22.0.tar.gz
"
